﻿$(function () {
    $("#file1").change(function (sender) {
        var files = sender.target.files;
        for (var i = 0; i < files.length; i++) {
            var finfo = files[i];
            var html = showFileInfo(finfo);
            $("#fileinfo").append(html);
        }
    });

    $("#dragfile").on('dragenter', function (e) {
        e.stopPropagation();
        e.preventDefault();
        $(this).css('border', '2px solid #0B85A1');
    }).on('dragover', function (e) {
        e.stopPropagation();
        e.preventDefault();
    }).on('dragout', function (e) {
        e.stopPropagation();
        e.preventDefault();
        $(this).css('border', 'solid 1px black');
    }).on('drop', function (e) {
        $(this).css('border', '2px dotted #0B85A1');
        e.preventDefault();
        var files = e.originalEvent.dataTransfer.files;
        for (var i = 0; i < files.length; i++) {
            var finfo = files[i];
            var html = showFileInfo(finfo);
            $("#fileinfo2").append(html);
        }
    });
});

function showFileInfo(fileobj) {
    var size = (fileobj.size / 1024).toFixed(2) + "KB";
    var html = "<div>";
    html += "文件名：" + fileobj.name + "<br />";
    html += "文件大小：" + size + "<br />";
    html += "文件类型：" + fileobj.type + "<br />";
    html += "最后修改时间：" + fileobj.lastModifiedDate + "<br />";
    html += "</div>";
    return html;
}